﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using JerrodSoft.Serialization.Xml;

namespace JerrodSoft.Tests
{
    [TestClass]
    public class SerializationTest
    {
        private readonly XmlSerializer Serializer = new XmlSerializer();

        [TestMethod]
        public void SerializeRootList()
        {
            List<string> items = new List<string>();
            items.Add("Jerrod");
            items.Add("Something Else");

            var result = Serializer.Serialize(items);

            Console.WriteLine(System.Xml.Linq.XElement.Parse(result));
            Assert.IsTrue(true);
        }

        [TestMethod]
        public void SerializeDeserializeRootList()
        {
            List<string> items = new List<string>()
            {
                "Jerrod",
                "Something Else"
            };
            int count = items.Count;

            var result = Serializer.Serialize(items);
            Console.WriteLine("Serialized:");
            Console.WriteLine(System.Xml.Linq.XElement.Parse(result));

            items = Serializer.DeSerialize<List<string>>(result);

            if (items.Count == count)
                Assert.IsTrue(true);
            else
                Assert.IsTrue(false);
        }

        [TestMethod]
        public void SerializeCustomCollection()
        {
            JerrodSoft.Tests.TestClasses.CustomCollection awesomeCollection = new TestClasses.CustomCollection();
            awesomeCollection.Add("Jerrod");
            awesomeCollection.Add("Other Stuff");

            var result = Serializer.Serialize(awesomeCollection);
            Console.WriteLine(System.Xml.Linq.XElement.Parse(result));
            Assert.IsTrue(true);
        }

        [TestMethod]
        public void SerializeCustomCollectionThenDeSerialize()
        {
            JerrodSoft.Tests.TestClasses.CustomCollection awesomeCollection = new TestClasses.CustomCollection();
            awesomeCollection.Add("Jerrod");
            awesomeCollection.Add("Other Stuff");

            int count = awesomeCollection.Count;
            var result = Serializer.Serialize(awesomeCollection);
            Console.WriteLine(System.Xml.Linq.XElement.Parse(result));

            awesomeCollection = Serializer.DeSerialize<JerrodSoft.Tests.TestClasses.CustomCollection>(result);

            if (count == awesomeCollection.Count)
                Assert.IsTrue(true);
            else
                Assert.IsTrue(false);
        }

        [TestMethod]
        public void SerializeObjectWithAllPrimitiveTypes()
        {
            var item = JerrodSoft.Tests.TestClasses.ClassWithAllPrimitiveTypes.GenerateMock();
            var result = Serializer.Serialize(item);
            Console.WriteLine(System.Xml.Linq.XElement.Parse(result).ToString());
            Assert.IsTrue(true);
        }

        [TestMethod]
        public void SerializeThenDeserializeObjectWithAllPrimitiveTypes()
        {
            var item = JerrodSoft.Tests.TestClasses.ClassWithAllPrimitiveTypes.GenerateMock();
            var result = Serializer.Serialize(item);
            Console.WriteLine(System.Xml.Linq.XElement.Parse(result).ToString());

            item = Serializer.DeSerialize<JerrodSoft.Tests.TestClasses.ClassWithAllPrimitiveTypes>(result);
            Assert.IsTrue(true);
        }

        [TestMethod]
        public void SerializeEnum()
        {
            JerrodSoft.Tests.TestClasses.MyMadeUpEnum x = TestClasses.MyMadeUpEnum.D;
            var result = Serializer.Serialize(x);
            Console.WriteLine(result);
            Assert.IsTrue(true);
        }
    }
}
